home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.11 Nov 90 / Transition Source / Demo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-28  |  10.5 KB  |  437 lines  |  [TEXT/KAHL]

  1. /************************************/
  2. /* File: Demo.c
  3. Function: Demo Window functions */
  4. /************************************/
  5. /* #include files */
  6. #include "General.h"
  7. #include "Demo.h"
  8. #include "Transition.h"
  9.  
  10. /* global variables */
  11. int dChk;
  12. int pChk;
  13. int cChk;
  14. int wipeMode;
  15. int wipePart;
  16. WindowPtr MyWindow;
  17.  
  18. /* static variables and function prototypes */
  19. static void  Do_A_Button(ControlHandle    theControl);
  20.  
  21. static Rect srcR = {21, 11, 141, 141};
  22. static Rect dstR = {21, 261,141, 391};
  23. static long elapsedTime;
  24.  
  25. /************************************/
  26. /* routines:
  27.     • void  Init_Demo()
  28.     • void  UpDate_Demo(whichWindow)
  29.     • void Open_Demo()
  30.     • static void  Do_A_Button(theControl)
  31.     • void  Do_Demo(myEvent)
  32.     */
  33. /************************************/
  34.  
  35. /************************************/
  36. /* void  Init_Demo()
  37.     initializes demo window */
  38. /************************************/
  39. void  Init_Demo()
  40. {
  41. MyWindow = NIL;
  42. dChk = pChk = cChk = 1;
  43. wipeMode = srcCopy;
  44. wipePart = 1;
  45. elapsedTime = 0;
  46. } /* void  Init_Demo() */
  47.  
  48. /************************************/
  49. /* void  UpDate_Demo(whichWindow)
  50.     updates demo window */
  51. /************************************/
  52. void  UpDate_Demo(whichWindow)
  53. WindowPtr  whichWindow;
  54. {
  55. WindowPtr   SavePort;
  56. Rect tempRect;
  57. Str255 sTemp;
  58. Str255 destinationStr = "\pDestination=>";
  59. Str255 sourceStr = "\p<=Source";
  60.     
  61. if ((MyWindow != NIL)  &&  (MyWindow == whichWindow)) { /* update demo window */
  62.     GetPort(&SavePort);
  63.     SetPort(MyWindow);
  64.  
  65.     /* draw frames */
  66.     SetRect(&tempRect, 260,20,392,142);
  67.     FrameRect(&tempRect);
  68.     SetRect(&tempRect, 10,20,142,142);
  69.     FrameRect(&tempRect);
  70.     
  71.     /* draw source image */
  72.     InsetRect(&tempRect, 5, 5);
  73.     FrameRect(&tempRect);
  74.     FillRect(&tempRect, ltGray);
  75.     SetRect(&tempRect, 20,112,40,132);
  76.     PenSize(4, 2);
  77.     PenMode(patBic);
  78.     FrameOval(&tempRect);
  79.     FillOval(&tempRect, dkGray);
  80.     PenMode(patOr);
  81.     PenSize(2,2);
  82.     MoveTo(30, 30);
  83.     LineTo(35, 60);
  84.     LineTo(120, 120);
  85.     PenNormal();        
  86.     SetRect(&tempRect, 110,30,130,50);
  87.     FrameRect(&tempRect);
  88.     FillRect(&tempRect, white);
  89.     
  90.     /* Draw text stuff */
  91.     TextFont(systemFont);
  92.     SetRect(&tempRect, 160,120,250,140);
  93.     TextBox(&destinationStr[1], destinationStr[0], &tempRect, teJustLeft);
  94.     SetRect(&tempRect, 150,30,210,50);
  95.     TextBox(&sourceStr[1], sourceStr[0], &tempRect, teJustLeft);
  96.     
  97.     /* Draw information */
  98.     SetRect(&tempRect, 10, 145, 300, 210);
  99.     FillRect(&tempRect, white);
  100.     MoveTo(10, 160);
  101.     switch (dChk) {
  102.         case DoWipeTopBottm:
  103.             DrawString("\pWipe Top=>Down");
  104.             MoveTo(10, 175);
  105.             DrawString("\pPartitions:");
  106.             NumToString((long) wipePart, &sTemp);
  107.             MoveTo(80, 175);
  108.             DrawString(sTemp);
  109.             break;
  110.         case DoWipeBottomTop:
  111.             DrawString("\pWipe Down=>Up");
  112.             MoveTo(10, 175);
  113.             DrawString("\pPartitions:");
  114.             NumToString((long) wipePart, &sTemp);
  115.             MoveTo(80, 175);
  116.             DrawString(sTemp);
  117.             break;
  118.         case DoWipeLeftRight:
  119.             DrawString("\pWipe Left=>Right");
  120.             MoveTo(10, 175);
  121.             DrawString("\pPartitions:");
  122.             NumToString((long) wipePart, &sTemp);
  123.             MoveTo(80, 175);
  124.             DrawString(sTemp);
  125.             break;
  126.         case DoWipeRightLeft:
  127.             DrawString("\pWipe Right=>Left");
  128.             NumToString((long) wipePart, &sTemp);
  129.             MoveTo(80, 175);
  130.             DrawString(sTemp);
  131.             MoveTo(10, 175);
  132.             DrawString("\pPartitions:");
  133.             break;
  134.         case DoPageFlipDown:
  135.             DrawString("\pPageFlipDown");
  136.             NumToString((long) wipePart, &sTemp);
  137.             MoveTo(80, 175);
  138.             DrawString(sTemp);
  139.             MoveTo(10, 175);
  140.             DrawString("\pPartitions:");
  141.             break;
  142.         case DoPageFlipRight:
  143.             DrawString("\pPageFlipRight");
  144.             NumToString((long) wipePart, &sTemp);
  145.             MoveTo(80, 175);
  146.             DrawString(sTemp);
  147.             MoveTo(10, 175);
  148.             DrawString("\pPartitions:");
  149.             break;
  150.         case DoIrisWipe:
  151.             DrawString("\pIris Wipe");
  152.             MoveTo(10, 175);
  153.             switch (pChk) {
  154.                 case 1:
  155.                     DrawString("\pCircle in");
  156.                     break;
  157.                 case 2:
  158.                     DrawString("\pCircle out");
  159.                     break;
  160.                 case 3:
  161.                     DrawString("\pTriangle");
  162.                     break;
  163.                 case 4:
  164.                     DrawString("\pOdd Shape");
  165.                     break;
  166.                 }
  167.             break;
  168.         case DoFadeWipe:
  169.             DrawString("\pFade Wipe");
  170.             MoveTo(10, 175);
  171.             switch (pChk) {
  172.                 case 1:
  173.                     DrawString("\pRandom 1");
  174.                     break;
  175.                 case 2:
  176.                     DrawString("\pRandom 2");
  177.                     break;
  178.                 case 3:
  179.                     DrawString("\pDiagonal");
  180.                     break;
  181.                 case 4:
  182.                     DrawString("\pVertical");
  183.                     break;
  184.                 }
  185.             break;
  186.         }
  187.         
  188.     MoveTo (10, 190);
  189.     switch (cChk) {
  190.         case 1:
  191.             DrawString("\psrcCopy");
  192.             break;
  193.         case 2:
  194.             DrawString("\psrcOr");
  195.             break;
  196.         case 3:
  197.             DrawString("\psrcXor");
  198.             break;
  199.         case 4:
  200.             DrawString("\psrcBIC");
  201.             break;
  202.         case 5:
  203.             DrawString("\pnotSrcCopy");
  204.             break;
  205.         case 6:
  206.             DrawString("\pnotSrcOr");
  207.             break;
  208.         case 7:
  209.             DrawString("\pnotSrcXor");
  210.             break;
  211.         case 8:
  212.             DrawString("\pnotSrcBic");
  213.             break;
  214.         }
  215.         
  216.     MoveTo(10, 205);
  217.     DrawString("\pTime in ticks:");
  218.     NumToString((long) elapsedTime, &sTemp);
  219.     MoveTo(100, 205);
  220.     DrawString(sTemp);
  221.             
  222.     TextFont(applFont);
  223.     
  224.     DrawControls(MyWindow);
  225.     SetPort(SavePort);
  226.     } /* update demo window */
  227. } /* void  UpDate_Demo(whichWindow) */
  228.  
  229. /************************************/
  230. /* void Open_Demo()
  231.     opens demo window */
  232. /************************************/
  233. void Open_Demo()
  234. {
  235. Rect    tempRect;
  236. ControlHandle tempControl;
  237.  
  238. if (MyWindow == NIL) { /* create demo window */
  239.     MyWindow = GetNewWindow(1,NIL, WindowInFront);
  240.     tempRect = MyWindow->portRect;
  241.     PositionRect(&tempRect, &(screenBits.bounds), CENTER, CENTER);
  242.     MoveWindow(MyWindow, tempRect.left, tempRect.top, TRUE);
  243.     SetPort(MyWindow);
  244.     
  245.     /* Make  buttons */
  246.     tempControl = GetNewControl(TransitionBtnRef,MyWindow);
  247.     tempControl = GetNewControl(EraseImageBtnRef,MyWindow);
  248.     tempControl = GetNewControl(DrawImageBtnRef,MyWindow);
  249.     
  250.     ShowWindow(MyWindow);
  251.     SelectWindow(MyWindow);
  252.     } /* create demo window */
  253. else
  254.     SelectWindow(MyWindow); /* show demo window */
  255. } /* void Open_Demo() */
  256.  
  257. /************************************/
  258. /* static void  Do_A_Button(theControl)
  259.     handles button in demo window */
  260. /************************************/
  261. static void  Do_A_Button(theControl)
  262. ControlHandle theControl;
  263. {
  264. short    RefCon;
  265. Rect tempRect;
  266. Rect infoRect = {145, 10, 300, 210};
  267. PolyHandle thePoly;
  268. RgnHandle maskRgn, irisRgn, iris2Rgn;
  269. long startTicks, stopTicks;
  270.  
  271. HiliteControl(theControl, 10);
  272.  
  273. RefCon = GetCRefCon(theControl);
  274. tempRect = dstR;
  275.  
  276. switch (RefCon) { /* Button Switch */
  277.     case TransitionBtnRef: /* transition button */
  278.         switch (dChk) { /* transition switch */
  279.             case DoWipeTopBottm:
  280.                 startTicks = TickCount();
  281.                 WipeTopBottom(&(MyWindow->portBits), &(MyWindow->portBits), &srcR, &dstR, wipeMode, NIL, wipePart, 0L);
  282.                 stopTicks = TickCount();
  283.                 break;
  284.                 
  285.             case DoWipeBottomTop:
  286.                 startTicks = TickCount();
  287.                 WipeBottomTop(&(MyWindow->portBits), &(MyWindow->portBits), &srcR, &dstR, wipeMode, NIL, wipePart, 0L);
  288.                 stopTicks = TickCount();
  289.                 break;
  290.                 
  291.             case DoWipeLeftRight:
  292.                 startTicks = TickCount();
  293.                 WipeLeftRight(&(MyWindow->portBits), &(MyWindow->portBits), &srcR, &dstR, wipeMode, NIL, wipePart, 0L);
  294.                 stopTicks = TickCount();
  295.                 break;
  296.                 
  297.             case DoWipeRightLeft:
  298.                 startTicks = TickCount();
  299.                 WipeRightLeft(&(MyWindow->portBits), &(MyWindow->portBits), &srcR, &dstR, wipeMode, NIL, wipePart, 0L);
  300.                 stopTicks = TickCount();
  301.                 break;
  302.                 
  303.             case DoIrisWipe:
  304.                 maskRgn = NewRgn();
  305.                 RectRgn(maskRgn, &dstR);
  306.                 iris2Rgn = NewRgn();
  307.                 irisRgn = NewRgn();
  308.                 OpenRgn();
  309.                 switch (pChk) { /* iris switch */
  310.                     case 1:
  311.                         FrameOval(&tempRect);
  312.                         CloseRgn(irisRgn);
  313.                         InsetRgn(irisRgn, -20, -20);
  314.                         CopyRgn(irisRgn, iris2Rgn);
  315.                         InsetRgn(irisRgn, -1, -1);
  316.                         DiffRgn(irisRgn, iris2Rgn, irisRgn);
  317.                         break;
  318.                     case 2:
  319.                         FrameOval(&tempRect);
  320.                         CloseRgn(irisRgn);
  321.                         InsetRgn(irisRgn, 40, 40);
  322.                         break;
  323.                     case 3:
  324.                         MoveTo(261, 21);
  325.                         LineTo(261, 141);
  326.                         LineTo(391, 141);
  327.                         LineTo(261, 21);
  328.                         CloseRgn(irisRgn);
  329.                         OffsetRgn(irisRgn, 10, -10);
  330.                         CopyRgn(irisRgn, iris2Rgn);
  331.                         InsetRgn(irisRgn, -1, -1);
  332.                         DiffRgn(irisRgn, iris2Rgn, irisRgn);
  333.                         break;
  334.                     case 4:
  335.                         SetRect(&tempRect, 281,41,301,61);
  336.                         FrameOval(&tempRect);
  337.                         SetRect(&tempRect, 351,41,371,61);
  338.                         FrameRect(&tempRect);
  339.                         MoveTo(281, 121);
  340.                         LineTo(371, 121);
  341.                         CloseRgn(irisRgn);
  342.                         CopyRgn(irisRgn, iris2Rgn);
  343.                         InsetRgn(irisRgn, -1, -1);
  344.                         DiffRgn(irisRgn, iris2Rgn, irisRgn);
  345.                         break;
  346.                     } /* iris switch */
  347.                 
  348.                 startTicks = TickCount();
  349.                 Iris(&(MyWindow->portBits), &(MyWindow->portBits), &srcR, &dstR, wipeMode, maskRgn, irisRgn, 0L);
  350.                 stopTicks = TickCount();
  351.                 DisposeRgn(irisRgn);
  352.                 DisposeRgn(iris2Rgn);
  353.                 DisposeRgn(maskRgn);
  354.                 break;
  355.                 
  356.             case DoFadeWipe:
  357.                 startTicks = TickCount();
  358.                 FadePat(&(MyWindow->portBits), &(MyWindow->portBits), &srcR, &dstR, wipeMode, NIL, pChk * 1000, 8, 0L);
  359.                 stopTicks = TickCount();
  360.                 break;
  361.                 
  362.             case DoPageFlipDown:
  363.                 startTicks = TickCount();
  364.                 PageFlipDown(&(MyWindow->portBits), &(MyWindow->portBits), &srcR, &dstR, NIL, pChk, 0L);
  365.                 stopTicks = TickCount();
  366.                 break;
  367.                 
  368.             case DoPageFlipRight:
  369.                 startTicks = TickCount();
  370.                 PageFlipRight(&(MyWindow->portBits), &(MyWindow->portBits), &srcR, &dstR, NIL, pChk, 0L);
  371.                 stopTicks = TickCount();
  372.                 break;
  373.             } /* transition switch */
  374.         elapsedTime = stopTicks - startTicks;
  375.         InvalRect(&infoRect);
  376.         break;
  377.  
  378.     case EraseImageBtnRef: /* erase button */
  379.         FillRect(&dstR, white);
  380.         break;
  381.  
  382.     case DrawImageBtnRef: /* Draw image button */
  383.         FillRect(&dstR, white);
  384.         thePoly = OpenPoly();
  385.         MoveTo(265, 25);
  386.         LineTo(265, 130);
  387.         LineTo(300, 75);
  388.         LineTo(265, 25);
  389.         ClosePoly();
  390.         PenSize(4, 2);
  391.         PenPat(dkGray);
  392.         FramePoly(thePoly);
  393.         FillPoly(thePoly, ltGray);
  394.         KillPoly(thePoly);
  395.         PenNormal();
  396.         SetRect(&tempRect, 350, 30, 380, 100);
  397.         PaintRoundRect(&tempRect, 5, 5);
  398.         PenMode(patCopy);
  399.         TextMode(srcXor);
  400.         MoveTo(300, 60);
  401.         DrawString("\pThis is NEAT");
  402.         TextMode(srcOr);
  403.         PenNormal();
  404.         break;
  405.  
  406.     default:
  407.         break;
  408.     } /* Button Switch */
  409.  
  410. HiliteControl(theControl, 0);
  411. } /* static void  Do_A_Button(theControl) */
  412.  
  413. /************************************/
  414. /* void  Do_Demo(myEvent)
  415.     handles events on demo window */
  416. /************************************/
  417. void  Do_Demo(myEvent)
  418. EventRecord    *myEvent;
  419. {
  420. short    code;
  421. WindowPtr    whichWindow;
  422. Point    myPt;
  423. ControlHandle    theControl;
  424.  
  425. if (MyWindow != NIL) { /* demo window only */
  426.     code = FindWindow(myEvent->where, &whichWindow);
  427.     
  428.     if ((MyWindow == whichWindow) &&
  429.             (myEvent->what == mouseDown) && (code == inContent)) { /* mousedown */
  430.         myPt = myEvent->where;
  431.         GlobalToLocal(&myPt);
  432.         code = FindControl(myPt, whichWindow, &theControl);
  433.         if (code == inButton) /* in button */
  434.             Do_A_Button(theControl);
  435.         }
  436.     }
  437. } /* void  Do_Demo(myEvent) */